package com.atguigu.pratice2;

import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

//线程不安全
public class NotSafeDemo {
//    public static void main(String[] args) {
////        ArrayList<String> list = new ArrayList<>();
////        Vector<String> list = new Vector<>();
////        List<String> list = Collections.synchronizedList(new ArrayList<>());
//        List<String> list = new CopyOnWriteArrayList();
//        //循环三次，三个线程
//        for (int i = 1; i <= 100; i++) {
//            new Thread(() -> {
//                list.add(UUID.randomUUID().toString().substring(0,6));
//                System.out.println(list.toString());
//            }, String.valueOf(i)).start();
//        }
//
//    }
public static void main(String[] args) {
    //线程不安全
    ArrayList<String> list =new ArrayList<>();
 //   List<String> list =new Vector<>();
    for (int i = 0; i < 100; i++) {
        new Thread(() -> {
            list.add(UUID.randomUUID().toString().substring(1,7));
            System.out.println(list);
        }, String.valueOf(i)).start();
    }

}
}
